﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    <script language="javascript">
        function locatePoint() {
            var aCtrl = document.getElementById("txtContent");
            if (getOs() == "FF") {
                if (aCtrl.setSelectionRange) {
                    setTimeout(function () {
                        aCtrl.setSelectionRange(aCtrl.value.length, aCtrl.value.length);  //将光标定位在textarea的开头，需要定位到其他位置的请自行修改
                        aCtrl.focus();
                    }, 0);
                }
            } else if (aCtrl.createTextRange) {
                var tempText = aCtrl.createTextRange();
                tempText.moveStart('character', aCtrl.value.length);
                tempText.collapse(true);
                tempText.select();

            }
        }
        function getOs() {
            var OsObject = "";
            if (navigator.userAgent.indexOf("MSIE") > 0) {
                return "IE";
            }
            if (isFirefox = navigator.userAgent.indexOf("Firefox") > 0) {
                return "FF";
            }
            if (isSafari = navigator.userAgent.indexOf("Safari") > 0) {
                return "Safari";
            }
            if (isCamino = navigator.userAgent.indexOf("Camino") > 0) {
                return "Camino";
            }
            if (isMozilla = navigator.userAgent.indexOf("Gecko/") > 0) {
                return "Gecko";
            }

        }  
    </script>
</head>
<body>
    <input type="text" value="http://toto369.net" onfocus="locatePoint()">
    <textarea id="txtContent">ssssssssssssssss</textarea>
</body>
</html>
